using System;
using System.Collections.Generic;
using System.Text;

using SD.LLBLGen.Pro.ORMSupportClasses;
using DatabaseAdapter;
using DatabaseGeneric;
using DatabaseGeneric.FactoryClasses;
using DatabaseGeneric.EntityClasses;
using DatabaseGeneric.RelationClasses;
using DatabaseGeneric.HelperClasses;

namespace Services
{
    public class SanPhamKhuon : Interfaces.ISanPhamKhuon
    {
        public EntityCollection<SanPhamKhuonEntity> FetchCollection()
        {
            EntityCollection<SanPhamKhuonEntity> collectionSanPhamKhuon = new EntityCollection<SanPhamKhuonEntity>();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(collectionSanPhamKhuon, null);
            }
            return collectionSanPhamKhuon;
        }

        public EntityCollection<SanPhamKhuonEntity> FetchCollection(ChungLoaiSanPhamEntity currentEntityChungLoaiSanPham)
        {
            EntityCollection<SanPhamKhuonEntity> collectionSanPhamKhuon = new EntityCollection<SanPhamKhuonEntity>();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(collectionSanPhamKhuon, new RelationPredicateBucket(SanPhamKhuonFields.MaChungLoaiSanPham == currentEntityChungLoaiSanPham.MaChungLoaiSanPham));
            }
            return collectionSanPhamKhuon;
        }

        public EntityCollection<SanPhamKhuonEntity> FetchCollection(string criteria, int option)
        {
            EntityCollection<SanPhamKhuonEntity> collectionSanPhamKhuon = new EntityCollection<SanPhamKhuonEntity>();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                switch (option)
                {
                    case 1:
                        adapter.FetchEntityCollection(collectionSanPhamKhuon, new RelationPredicateBucket(SanPhamKhuonFields.LoaiSanPhamKhuon == criteria));
                        break;
                }
            }
            return collectionSanPhamKhuon;
        }

        public SanPhamKhuonEntity FetchEntity(SanPhamKhuonEntity currentEntitySanPhamKhuon)
        {
            SanPhamKhuonEntity entitySanPhamKhuon = new SanPhamKhuonEntity(currentEntitySanPhamKhuon.MaSanPhamKhuon);
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntity(entitySanPhamKhuon);
            }
            return entitySanPhamKhuon;
        }

        public int SaveCollection(EntityCollection<SanPhamKhuonEntity> currentCollectionSanPhamKhuon)
        {
            int cntSave = 0;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                cntSave = adapter.SaveEntityCollection(currentCollectionSanPhamKhuon);
            }
            return cntSave;
        }

        public bool SaveEntity(SanPhamKhuonEntity currentEntitySanPhamKhuon)
        {
            bool isSave = false;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                isSave = adapter.SaveEntity(currentEntitySanPhamKhuon);
            }
            return isSave;
        }

        public int DeleteCollection(EntityCollection<SanPhamKhuonEntity> currentCollectionSanPhamKhuon)
        {
            int cntDelete = 0;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.DeleteEntityCollection(currentCollectionSanPhamKhuon);
            }
            return cntDelete;
        }

        public bool DeleteEntity(SanPhamKhuonEntity currentEntitySanPhamKhuon)
        {
            bool isDelete = false;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                isDelete = adapter.DeleteEntity(currentEntitySanPhamKhuon);
            }
            return isDelete;
        }

        public System.Data.DataTable Report(ChungLoaiSanPhamEntity currentEntityChungLoaiSanPham)
        {
            System.Data.DataTable dtSanPhamKhuon = new System.Data.DataTable();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                dtSanPhamKhuon = RetrievalProcedures.SanPhamKhuonByChungLoaiSanPhamPro(currentEntityChungLoaiSanPham.MaChungLoaiSanPham, adapter);
            }
            return dtSanPhamKhuon;
        }
    }
}
